import java.util.HashSet;
import java.util.Set;

/**
 * Created With IntelliJ IDEA
 * Description:leetdoce：771. 宝石与石头
 * <a href="https://leetcode.cn/problems/jewels-and-stones/">...</a>
 * User: DELL
 * Data: 2023-02-18
 * Time: 22:52
 */
public class Solution {
    /**
     * 利用HashSet来实现
     * @param jewels
     * @param stones
     * @return
     */
    public int numJewelsInStones(String jewels, String stones) {
        int num = 0;
        Set<Character> set = new HashSet<>();
        //将jewels加入set中
        for (int i = 0; i < jewels.length(); i++) {
            set.add(jewels.charAt(i));
        }
        //统计宝石数目
        for (int i = 0; i < stones.length(); i++) {
            if (set.contains(stones.charAt(i))) {
                num++;
            }
        }
        return num;
    }
}
